package com.example.project10;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesUtil {
    private static final String PREF_NAME = "user_prefs";
    private static final String KEY_TOKEN = "auth_token";
    private static final String KEY_AUTO_LOGIN = "auto_login";
    
    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }
    
    public static void saveToken(Context context, String token) {
        SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        editor.putString(KEY_TOKEN, token);
        editor.apply();
    }
    
    public static String getToken(Context context) {
        return getSharedPreferences(context).getString(KEY_TOKEN, null);
    }
    
    public static void saveAutoLogin(Context context, boolean autoLogin) {
        SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        editor.putBoolean(KEY_AUTO_LOGIN, autoLogin);
        editor.apply();
    }
    
    public static boolean isAutoLoginEnabled(Context context) {
        return getSharedPreferences(context).getBoolean(KEY_AUTO_LOGIN, false);
    }
    
    public static void clearToken(Context context) {
        SharedPreferences.Editor editor = getSharedPreferences(context).edit();
        editor.remove(KEY_TOKEN);
        editor.remove(KEY_AUTO_LOGIN);
        editor.apply();
    }
}